package com.service.impl;

import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.bean.UserList;
import com.dao.UserListDao;
import com.service.UserListService;
import com.util.LoggerUtil;
import com.util.Pager;
@Component
public class UserListServiceImpl implements UserListService{
	public static Logger logger=Logger.getLogger(UserListServiceImpl.class);
	@Autowired
	private UserListDao userListDao;
	@Override
	public Map<String, Object> selectByUserName(String id,String userId,JSONObject logs) {
		Map<String, Object> map=new HashMap<String, Object>();
		try {
			UserList userList=userListDao.selectByUserName(id,userId);
			if(userList!=null){
				map.put("result","success" );
				map.put("rows", userList);
				LoggerUtil.backlogsSuccess(logs, logger);
			}else{
				map.put("result", "false");
				LoggerUtil.backlogsFalseNOData(logs, logger);
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		return map;
	}

	@Override
	public Map<String, Object> selectByOfficial(Integer curPage,
			Integer pageSize,String userId,JSONObject logs) {
		Map<String, Object> map=new HashMap<String, Object>();
		try {
			Pager<UserList> pager=userListDao.selectByOfficial(curPage, pageSize,userId);
			if(pager!=null&pager.getData().size()>0){
				map.put("result","success" );
				map.put("rows", pager);
				LoggerUtil.backlogsSuccess(logs, logger);
			}else{
				map.put("result", "false");
				LoggerUtil.backlogsFalseNOData(logs, logger);
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		return map;
	}

	@Override
	public Map<String, Object> selectByStar(Integer curPage, Integer pageSize,String userId,JSONObject logs) {
		Map<String, Object> map=new HashMap<String, Object>();
		try {
			Pager<UserList> pager=userListDao.selectByStar(curPage, pageSize,userId);
			if(pager!=null&pager.getData().size()>0){
				map.put("result","success" );
				map.put("rows", pager);
				LoggerUtil.backlogsSuccess(logs, logger);
			}else{
				map.put("result", "false");
				LoggerUtil.backlogsFalseNOData(logs, logger);
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		return map;
	}
	@Override
	public Map<String, Object> selectByHost(Integer curPage, Integer pageSize,String userId,JSONObject logs) {
		Map<String, Object> map=new HashMap<String, Object>();
		try {
			Pager<UserList> pager=userListDao.selectByHost(curPage, pageSize,userId);
			if(pager!=null&pager.getData().size()>0){
				map.put("result","success" );
				map.put("rows", pager);
				LoggerUtil.backlogsSuccess(logs, logger);
			}else{
				map.put("result", "false");
				LoggerUtil.backlogsFalseNOData(logs, logger);
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		return map;
	}

	@Override
	public Map<String, Object> selectFindLine(Integer curPage, Integer pageSize,JSONObject logs) {
		Map<String, Object> map=new HashMap<String, Object>();
		try {
			Pager<UserList> pager=userListDao.selectFindLine(curPage, pageSize);
			if(pager!=null&pager.getData().size()>0){
				map.put("result","success" );
				map.put("rows", pager);
				LoggerUtil.backlogsSuccess(logs, logger);
			}else{
				map.put("result", "false");
				LoggerUtil.backlogsFalseNOData(logs, logger);
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		return map;
	}

}
